const app = getApp()
const url = app.globalData.url
const url1 = app.globalData.url1
var userTel = ""
var longitude = ""
var latitude = ""
var addr = {}
var billEmail = ""
var billTt = ""
var billSh = "l"
var billType = ""
var smenuid = ''
var menuid = ''
var eqBrand = '' // 品牌
var eqType = "" //类型
var eqModel = "64G" //型号
var eqColor = "#FFF"
var orderId = ''
var orderPrice = ''
var ordertype = ''
var brandId=''
var index

Page({

  /**
   * 页面的初始数据
   */
  data: {
    enlists: [1, 2, 3, 2, 2, 22, 1, 2],
    temp: "myenlist",
    isRouter:false,
    btnIndex: 0,
    addrlist: [],
    flag: true,
    names: "我的",
    kpIndex: 0,
    color1: "#fff",
    color2: "#fff",
    addIndex1: 0,
    addIndex: 0,
    addIndex2: 0,
    showModalStatus: false,
    tempFilePaths: [],
    neicunindex: 0,
    addIndex:0,
    colorIndex: 0,
    showDetails: false,
    selectAddress:false
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var user = wx.getStorageSync('user')
    userTel = user.wxUsersAccount
    let that = this
    index = options.index
    console.log(options)
    if (options.selectAddress){
    that.setData({
      selectAddress: options.selectAddress
    })
    }
    that.setData({
      valIndex: index,
      temp: options.page,
      usersWatar: user.wxUsersAvatarUrl,
      isRouter:false
    })
   that.touch(index)
    wx.getSystemInfo({
      success: function (res) {
        var clientHeight = res.windowHeight,
          clientWidth = res.windowWidth,
          rpxR = 750 / clientWidth;
        var calc = clientHeight * rpxR - 180;
        console.log(calc)
        that.setData({
          winYheight: calc
        });
      }
    });
  },
  getAccOrder() {
    const that = this
    wx.request({
      url: url + '/cw_order/my_comment',
      data: {
        account: userTel
      },
      header: {
        "content-type": "application/json"
      },
      success(res) {
        console.log("获取评价")
        console.log(res.data)
        if (res.data.code === 1) {
          that.setData({
            cssOrder: res.data.data.orderMasterList,
            isRouter:false
          })
        }else{
          that.setData({
            isRouter:true
          })
        }
      }
    })
  },

  getpicture: function() {
    var that = this;
    wx.showActionSheet({
      itemList: ['从相册中选择', '拍照'],
      itemColor: "#CED63A",
      success: function(res) {
        if (!res.cancel) {
          if (res.tapIndex == 0) {
            that.chooseWxImage('album')
          } else if (res.tapIndex == 1) {
            that.chooseWxImage('camera')
          }
        }
      }
    })
  },
  chooseWxImage: function(type) {
    var that = this;
    wx.chooseImage({
      count: 3 - this.data.tempFilePaths.length,
      sizeType: ['original', 'compressed'],
      sourceType: [type],
      success: function(res) {
        console.log(res);

        //上传到自己的服务器
        var filePaths = res.tempFilePaths;
        //多张图片
        for (var index in filePaths) {
          console.log(filePaths[index]);

          wx.uploadFile({
            url: url + '/photo/add_img',
            filePath: filePaths[index],
            name: 'files',
            formData: {
              'user': 'test'
            },
            success: function(res) {

              console.log('123qwe')
              //为空赋值
              for (var i = 0; i < 4; i++) {
                if (that.data.tempFilePaths[i] == null) {
                  console.log("fileq:" + that.data.tempFilePaths[i]);
                  that.data.tempFilePaths[i] = res.data;
                  console.log("fileh:" + that.data.tempFilePaths[i]);
                  break;
                }
              }

              that.setData({

                tempFilePaths: that.data.tempFilePaths,
                length: that.data.tempFilePaths.length
              })
            }


          })

        }

      }
    })
  },
  // 评论num
  getComNum() {
    const that = this
    wx.request({
      url: url + '/comment/count_account',
      data: {
        account: userTel
      },
      header: {
        "content-type": "application/json"
      },
      success(res) {
        console.log("获取评价数量")
        console.log(res.data)
        if (res.data.code === 1) {
          that.setData({
            allComment: res.data.data.count1,
            withPic: res.data.data.count2,
            followComment: res.data.data.count3
          })
        }
      }
    })
  },
  toaccess(e) {
    wx.navigateTo({
      url: '../access/access?orderid=' + e.currentTarget.dataset.id,
    })
  },
  //亲友号、
  // 添加亲友
  addFriend() {
    wx.navigateTo({
      url: '../friends/addOne/addOne',
    })
  },
  // 获取亲友
  getmyFriend() {
    const that = this
    wx.request({
      url: url + '/relatives_friends/select',
      data: {
        number: userTel
      },
      header: {
        "content-type": "application/json"
      },
      success(res) {
        console.log("获取亲友号")
        console.log(res.data)
        if (res.data.code === 1) {
          that.setData({
            friends: res.data.data.relativesFriendsList
          })
        }
      }
    })
  },
  //设备
  moreOther(e) {
    let that = this
    console.log(e.currentTarget.dataset.index + "-----index")
    console.log(e.currentTarget.dataset.url + "-----url")
    that.setData({
      valIndex: e.currentTarget.dataset.index,
      temp: e.currentTarget.dataset.url,
      isRouter: false
    })
    index = e.currentTarget.dataset.index
    that.touch(index)
  },
  touch(index){
    const that=this
    if (index == 0) {
      that.getEquipment(4)
      that.getEquipment(5)
      that.getEquipment(6)
      that.getEquipment(7)
      console.log("设备列表")
    } else if (index == 1) {
      that.setData({
        btnIndex:0
      })
      that.getEnlist1()
      console.log("师傅列表")
    } else if (index == 2) {
      that.getCouponPapers()
      that.getCoupon()
      console.log("优惠卷列表")
    } else if (index == 3) {
      that.getmyFriend()
      console.log("亲友号")
    } else if (index == 4) {
      that.getAddr();
      console.log("地址")
    } else if (index == 5) {

    } else if (index == 6) {
      that.getComNum()
      that.getAccOrder()
      console.log("我的 评价")
    }
  },
  addequipment(e) {
    this.showPopup()
    console.log(e)
    menuid = e.currentTarget.id
    this.getpictures(menuid)
    this.getShebeiType(menuid)
    this.setData({
      equipmentShow: menuid,
      showDetails: true,
      addQuipmenName:e.currentTarget.dataset.name,
      pcolor:"白色",
      pmodel:"64G"
    })
  },
  getpictures(menuId) {
    const that = this
    wx.request({
      url: url + '/menu/menus_icon',
      data: {
        mid: menuId
      },
      header: {
        "content-type": "application/json"
      },
      success(res) {
        console.log("查询图片")
        console.log(res)
        if (res.data.code == 1) {
          that.setData({
            imgs: res.data.data.icon
          })
        }
      }

    })
  },
  selectRank(e) {
    const that = this
    smenuid = e.currentTarget.dataset.sid
    eqType = e.currentTarget.dataset.type
    that.getbrans(e.currentTarget.dataset.sid)
    that.setData({
      addIndex: e.currentTarget.dataset.index,
      eqtype:eqType,
      checkedimg1: e.currentTarget.dataset.img
    })
  },
  selectBrand(e) {
    const that = this
    console.log("选择品牌时")
    console.log(e)
    eqBrand = e.currentTarget.dataset.brand
    const type = e.currentTarget.dataset.type
    brandId = e.currentTarget.dataset.id
    if (type) {
      that.setData({
        checkedimg1: e.currentTarget.dataset.img
      })
    } else {
      that.setData({
        checkedimg2: e.currentTarget.dataset.img
      })
    }
    that.setData({
      addIndex1: e.currentTarget.dataset.index,
      eqbrand:eqBrand
    })
  },

  getModels(e) {
    const that = this
    eqModel = e.currentTarget.dataset.name
    that.setData({
      neicunindex: e.currentTarget.dataset.index,
      pmodel:eqModel
    })
  },
  getColor(e) {
    const that = this
    var color=e.currentTarget.dataset.name
    if (color == "#fff") {
      eqColor = "白色"
    } else if (color == "#000") {
      eqColor = "黑色"
    } else if (color == "#ECE2AD") {
      eqColor = "金色"
    } else if (color == "#EFB2E1") {
      eqColor = "粉色"
    }
    that.setData({
      colorIndex: e.currentTarget.dataset.index,
      pcolor:eqColor
    })
  },
  //确认添加设备
  submitAddsb() {
    const that = this

    console.log(eqBrand == null)
    if (eqBrand == '') {
      wx.showToast({
        title: '请选择品牌类型',
        icon: "loading",
        duration: 1000
      })
    } else {
      wx.request({
        url: url + '/Equipment/addEquipment',
        data: {
          wxUsersAccount: userTel,
          menuId: menuid,
          typeId: smenuid,
          eqType: eqType,
          eqBrand: eqBrand,
          eqModel: eqModel,
          eqColor: eqColor,
          brandId: brandId
        },
        method: "get",
        header: {
          "content-type": "application/json"
        },
        success(res) {
          console.log(res)
          if (res.data.code == 0) {
            wx.showToast({
              title: '添加成功',
              icon: "success",
              duration: 1000
            })
            that.popupTap()
            that.getEquipment(menuid)
          } else {
            wx.showToast({
              title: '添加失败',
              icon: "success",
              duration: 1000
            })
          }
        }
      })
    }
  },
  getDetails(e) {
    this.getequipDetails(e.currentTarget.id)
    this.showPopup()
    this.setData({
      showDetails: false
    })
  },
  //设备类型添加设备的
  getShebeiType(data) {
    const that = this
    wx.request({
      url: url + '/menu/menus_pid',
      data: {
        pid: data
      },
      header: {
        'content-type': 'application/json'
      },
      success(res) {
        console.log("获取二级菜单：")
        console.log(res.data)

        if (res.data.code == 1) {
          that.setData({
            types: res.data.data.menus,
            eqtype: res.data.data.menus[0].menuName
          })
          smenuid = res.data.data.menus[0].menuId
          eqType = res.data.data.menus[0].menuName
          that.getbrans(res.data.data.menus[0].menuId,data)
          if (data != 5) {
            that.setData({
              checkedimg1: res.data.data.menus[0].menuImg1
            })
          }
       
        } else {
          wx.showToast({
            title: '加载失败',
            icon: "loading",
            duration: 1000
          })
        }
      }
    })
  },
  //加载品牌类型
  getbrans(data,id) {
    const that = this
    wx.request({
      url: url + '/menu/menus_pid',
      data: {
        pid: data
      },
      header: {
        'content-type': 'application/json'
      },
      success(res) {
        console.log("获取品牌类型：")
        console.log(res.data)

        if (res.data.code == 1) {
          eqBrand = res.data.data.menus[0].menuName
          that.setData({
            brans: res.data.data.menus,
            eqbrand:eqBrand,
            addIndex1:0
          })
          brandId = res.data.data.menus[0].menuId
          if (id == 5) {
            that.setData({
              checkedimg1: res.data.data.menus[0].menuImg1,
              checkedimg2: ''
            })
          } else {
            that.setData({
            
              checkedimg2: res.data.data.menus[0].menuImg1
            })
          }
        } else {
          eqBrand = ''
          eqModel = ''
          that.setData({
            brans: [],
            models: [],
            isTrue: false
          })
        }
      }
    })
  },

  // 维修师
  wxscheck(e) {
    const that = this
    that.setData({
      btnIndex: e.currentTarget.id
    })
    if (e.currentTarget.id == 0) {
      that.getEnlist1()
    } else {
      that.getEnlist()
    }
  },
  //取消关注
  cansleAttention(e) {
    var number = e.currentTarget.dataset.id
    const that = this
    wx.request({
      url: url + '/wx_users_engineer/delete',
      data: {
        wxUsersAccount: userTel, //用户平台账号
        engineerNumber: number // 维修师平台账号
      },
      method: "get",
      header: {
        "content-type": "application/json"
      },
      success(res) {
        console.log(res.data)
        if (res.data.code ===0) {
          wx.showToast({
            title: '取消成功',
            icon: "success",
            duration: 1000
          })
          //刷新
          that.getEnlist()
        } else {
          wx.showToast({
            title: '取消失败',
            icon: "loading",
            duration: 1000
          })
        }
      }
    })
  },
  //guanzhu
  guanzhu(e) {
    const that = this
    var number = e.currentTarget.dataset.id
    wx.request({
      url: url + '/wx_users_engineer/add_follow',
      data: {
        wxUsersAccount: userTel,//用户平台账号
        engineerNumber: number //维修师平台账号
      },
      header: {
        "content-type": "application/json"
      },
      success(res) {
        if (res.data.code === 0) {
          wx.showToast({
            title: '关注成功',
            icon: 'success',
            duration: 1000
          })
          that.getEnlist1()
        }else{
          wx.showToast({
            title: '关注失败',
            icon: "loading",
            duration: 1000
          })
        }
      }
    })
  },
  addAddr() {
    console.log("添加地址")
    const that = this
    that.showPopup()
  },
  selectAddress(e) {
    wx.setStorageSync("address", e.currentTarget.dataset.item)
    wx.navigateBack(1)
  },
  kpcheck(e) {
    const that = this
    that.setData({
      kpIndex: e.currentTarget.id
    })
    if (e.currentTarget.id == 0) {

    } else
    if (e.currentTarget.id == 1) {
      that.getbillOrder()
    } else {
      that.getbillOrder1()
    }
  },
  // 维修师我关注的
  getEnlist() {
    const that = this
    wx.request({
      url: url + '/wx_users_engineer/by_account',
      data: {
        account: userTel
      },
      method: "get",
      header: {
        "content-type": "application/json"
      },
      success(res) {
        console.log("我关注的")
        console.log(res.data)
        if (res.data.code === 1) {
          that.setData({
            enlists: res.data.data.engineerList,
            isRouter: false
          })
        } else {
          that.setData({
            enlists: [],
            isRouter: true
          })
        }
      }
    })
  },
  //维修师我用过的
  getEnlist1() {
    const that = this
    wx.request({
      url: url + '/wx_users_engineer/by_account_history',
      data: {
        account: userTel
      },
      method: "get",
      header: {
        "content-type": "application/json"
      },
      success(res) {
        console.log("维修师我关注的：")
        console.log(res.data)
        if (res.data.code === 1) {
          that.setData({
            enlists: res.data.data.engineerList,
            isRouter:false
          })
        } else {
          that.setData({
            enlists: [],
            isRouter:true
          })
        }
      }
    })
  },
  // 地址管理
  saveAddr() {
    const that = this
    var reg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/
    console.log(addr.addressName)
    console.log(location)
    console.log(location)
    if (addr.addressName == undefined || addr.addressPhone == undefined || addr.addressLocation == undefined || addr.addressDoorNumber == undefined) {

      wx.showToast({
        title: '地址填写不完整',
        icon: 'loading',
        duration: 3000
      })
    } else if (!reg.test(addr.addressPhone)) {
      wx.showToast({
        title: "手机格式不正确",
        icon: "loading",
        duration: 3000
      })
    } else {
      wx.request({
        url: url + '/address/insert',
        data: {
          wxUsersAccount: userTel,
          addressName: addr.addressName, //姓名
          addressSex: "", //性别
          addressPhone: addr.addressPhone, //手机
          addressLocation: addr.addressLocation, //地址
          addressDoorNumber: addr.addressDoorNumber, //详细地址
          addressLongitude: longitude, //经度
          addressLatitude: latitude, //纬度
        },
        header: {
          "content-type": "application/json"
        },
        success(res) {
          console.log("获取地址列表：")
          console.log(res.data)
          if (res.data.code === 0) {
            that.getAddr()
            that.hidePopup()
            wx.showToast({
              title: '添加成功',
              icon: "success",
              duration: 1000
            })
          } else {
            wx.showToast({
              title: '添加失败',
              icon: "loading",
              duration: 2000
            })
          }
        }
      })
    }
  },

  deleteAddr(e) {
    console.log(e)
    var id = e.currentTarget.id
    const that = this
    wx.request({
      url: url + '/address/delete',
      data: {
        addressId: id
      },
      header: {
        "content-type": "application/json"
      },
      success(res) {
        if (res.data.code == 0) {
          wx.showToast({
            title: '删除成功',
            duration: 1000,
            icon: "success"
          })
          that.getAddr();
        } else {
          wx.showToast({
            title: '操作失败',
            duration: 1000,
            icon: "loading"
          })
        }
      }
    })
  },
  //  设置默认、取消
  buildDefault(e) {
    var id = e.currentTarget.id
    const that = this
    wx.request({
      url: url + '/address/update_status',
      data: {

        addressId: id
      },
      header: {
        "content-type": "application/json"
      },
      success(res) {
        console.log(res)
        if (res.data.code == 0) {
          wx.showToast({
            title: '设置成功',
            duration: 1000,
            icon: "success"
          })

          that.getAddr();
        } else {
          wx.showToast({
            title: '操作失败',
            duration: 1000,
            icon: "loading"
          })
        }
      }
    })
  },
  selectAddr() {
    var that = this;

    wx.getSetting({
      success: (res) => {
        console.log(res);
        console.log(res.authSetting['scope.userLocation']);
        if (res.authSetting['scope.userLocation'] != undefined && res.authSetting['scope.userLocation'] != true) {//非初始化进入该页面,且未授权
          wx.showModal({
            title: '是否授权当前位置',
            content: '需要获取您的地理位置，请确认授权，否则下单等功能将无法使用',
            success: function (res) {
              if (res.cancel) {
                console.info("授权失败");

              } else if (res.confirm) {
                //village_LBS(that);
                wx.openSetting({
                  success: function (data) {
                    console.log(data);
                    if (data.authSetting["scope.userLocation"] == true) {
                      wx.showToast({
                        title: '授权成功',
                        icon: 'success',
                        duration: 5000
                      })
                      //再次授权，调用getLocationt的API

                    } else {
                      wx.showToast({
                        title: '授权失败',
                        icon: 'success',
                        duration: 5000
                      })
                    }
                  }
                })
              }
            }
          })
        }
      }
    })

    wx.chooseLocation({
      success: function (s) {
        console.log(s)
        location = s.address
        longitude = s.longitude
        latitude = s.latitude
        addr.addressLocation=s.address
        that.setData({
          location: s.address
        })
      },
    })

  },
  geo: function () {
    var _this = this;

        wx.chooseLocation({
          success: function (s) {
            console.log(s)
            addr.addressLocation = s.address
            longitude = s.longitude
            latitude = s.latitude
            _this.setData({
              location: s.address
            })
          },
          fail(){
          //  _this.selectAddr()
          }
        })
  
  },           
  getAddrName(e) {
    console.log(e)
    addr.addressName = e.detail.value
  },
  getAddrPhone(e) {
    addr.addressPhone = e.detail.value
  },
  getAddrDoornumber(e) {
    addr.addressDoorNumber = e.detail.value
  },

  //  获取地理列表
  getAddr() {
    const that = this
    wx.request({
      url: url + '/address/all_address',
      data: {
        account: userTel
      },
      header: {
        "content-type": "application/json"
      },
      success(res) {
        console.log("获取地址列表：")
        console.log(res.data)
        if (res.data.code === 1) {

          that.setData({
            addrlist: res.data.data.addressList,
            isRouter: false
          })

        } else {

          that.setData({
            addrlist: [],
            isRouter:true
          })

        }
      }
    })

  },

  //设备管理
  getEquipment(menuid) { //电脑4 手机5 家电6 办公7
    const that = this

    wx.request({
      url: url + '/Equipment/getListEquipment',
      data: {
        account: userTel,
        menuId: menuid
      },
      header: {
        "content-type": "application/json"
      },
      success(res) {
        console.log(res.data)
        if (res.data.code == 1) {
          if (menuid == 4) {
            that.setData({
              computers: res.data.data.equipment
            })
          } else if (menuid == 5) {
            that.setData({
              phones: res.data.data.equipment
            })
          } else if (menuid == 6) {
            that.setData({
              jiadian: res.data.data.equipment
            })
          } else if (menuid == 7) {

          }

        } else {
          if (menuid == 4) {
            that.setData({
              computers: []
            })
          } else if (menuid == 5) {
            that.setData({
              phones: []
            })
          } else if (menuid == 6) {
            that.setData({
              jiadian: []
            })
          }
        }
      }
    })
  },
  getequipDetails(id){
    const that = this
    wx.request({
      url: url + '/orderItem/by_sn',
      data: {
        sn: id
      },
      header: {
        "content-type": "application/json"
      },
      success(res) {
        if (res.data.code == 1) {
         that.setData({
           Equipmentdetails: res.data.data.equipment
         })
        }
      }
    })
  },
  deleteEq(e) {
    const that = this
    wx.request({
      url: url + '/Equipment/deleteEquipment',
      data: {
        equipmentId: e.currentTarget.id
      },
      header: {
        "content-type": "application/json"
      },
      success(res) {
        if (res.data.code == 0) {
          wx.showToast({
            title: '删除成功',
            icon: "success",
            duration: 1000
          })
          that.getEquipment(e.currentTarget.dataset.sid)
        }
      }
    })
  },

  // 弹窗

  // 弹出框
  tt: function() {
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "liner",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function() {
      animation.translateY(0).step()
      this.setData({

        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  hideModal: function() {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function() {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false

      })
    }.bind(this), 200)
  },

  //  优惠卷
  getCoupon() {
    const that = this
    wx.request({
      url: url + '/coupon/usr/list_coupon',
      data: {
        account: userTel
      },
      method: "get",
      header: {
        "content-type": "application/json"
      },
      success(res) {
        console.log("优惠卷")
        console.log(res.data)
        if (res.data.code === 1) {
          that.setData({
            coupons: res.data.data.couponUsrList,
            isRouter:false
          })
        }else{
          that.setData({
            isRouter:true
          })
        }
      }
    })
  },
  gotouse(){
    console.log("使用优惠卷")
      wx.navigateTo({
        
        url: '../index/index',
      })
  },
  getCouponPapers() {
    const that = this
    var user = wx.getStorageSync('user')
    wx.request({
      url: url + '/coupon/usr/count_account_usable',
      data: {
        account: user.wxUsersAccount
      },
      method: "get",
      header: {
        "content-type": "application/json"
      },
      success(res) {
        if (res.data.code === 1) {
          that.setData({
            papers: res.data.data.count,
            leftovers: res.data.data.money
          })
        }
      }
    })
  },


  back() {
    wx.navigateBack(1)
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    const that = this
    console.log(app.globalData.height + "-------onshow--height")
    app.editTabBar3();
    if(index==4){
    that.getAddr()

    }else if(index==3){
    that.getmyFriend()

    }else if(index==6){
    that.getAccOrder()

    }
  },

  addbill(e) {
    const that = this
    that.showPopup()
    orderId = e.currentTarget.dataset.id
    ordertype = e.currentTarget.dataset.type
    orderPrice = e.currentTarget.dataset.price
    that.setData({
      orders: orderId
    })
  },
  selectBilltype1() {

    console.log("单位")
    const that = this
    billType = "企业发票"
    that.setData({
      color1: "#A01DE3",
      color2: "#fff"
    })
  },
  selectBilltype2() {
    console.log("个人")
    billType = "个人发票"
    const that = this
    that.setData({
      color2: "#A01DE3",
      color1: "#fff"
    })
  },
  // 发票抬头
  getbillTt(e) {
    billTt = e.detail.value
  },
  // 发票税号
  getbillsh(e) {
    billSh = e.detail.value
  },
  // 邮箱
  getbillemail(e) {
    console.log(e)
    billEmail = e.detail.value
  },
  addbills() {
    const that = this
    var re = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;

    if (billEmail.length == 0 ||
      billTt.length == 0 || billType.length == 0) {
      wx.showToast({
        title: '请输入完整信息',
        icon: "loading",
        duration: 1000
      })
    } else if (!re.test(billEmail)) {
      wx.showToast({
        title: '邮箱不正确',
        icon: "loading",
        duration: 1000
      })
    } else if (billType == "单位" && billSh.length == 0) {
      wx.showToast({
        title: '请输入企业税号',
        icon: "loading",
        duration: 1000
      })
    } else {
      // 开票
      wx.request({
        url: url1+'/Invoice/KaiPIao',
        data: {
          orderId: orderId,
          invoiceType: billType,
          iHead: billTt,
          shuihao: billSh,
          youxiang: billEmail,
          iPrice: orderPrice,
          orderMenu: ordertype
        },
        header: {
          'content-type': "application/json"
        },
        method: "get",
        success(res) {
          console.log('订单开票数据')
          console.log(res.data)
          if (res.data.code == 1) {
            wx.showToast({
              title: '开票成功',
              icon: "loading",
              duration: 1000
            })
            that.popupTap()
            that.getbillOrder()

          } else {
            wx.showToast({
              title: '开票失败',
              icon: "loading",
              duration: 1000
            })
          }
        }
      })

    }
  },

  getbillOrder1() {
    const that = this
    wx.request({
      url: url1+'/Invoice/findOrderBill',
      data: {
        usesAccount: userTel
      },
      header: {
        'content-type': "application/json"
      },
      method: "get",
      success(res) {
        console.log('订单数据已开发票')
        console.log(res.data)
        if (res.data.code == 1) {
          that.setData({
            billOrder: res.data.data
          })
        } else {

        }
      }
    })
  },
  getbillOrder() {
    const that = this
    wx.request({
      url: url1+'/orders/findOrderNotBill',
      data: {
        usesAccount: userTel
      },
      header: {
        'content-type': "application/json"
      },
      method: "get",
      success(res) {
        console.log('订单数据')
        console.log(res.data)
        if (res.data.code == 1) {
          that.setData({
            billNot: res.data.data
          })
        } else {

        }
      }
    })
  },

  popupTap() {
    let popupComponent = this.selectComponent('.J_Popup');

    popupComponent && popupComponent.toggle(false);
  },

  showPopup() {
    let popupComponent = this.selectComponent('.J_Popup');
    /*popupComponent && popupComponent.show();*/
    popupComponent && popupComponent.toggle(true);
  },
  hidePopup() {
    let popupComponent = this.selectComponent('.J_Popup');
    //popupComponent && popupComponent.hide();
    popupComponent && popupComponent.toggle();
    this.popupTap()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})